'use strict';

/* Controllers */
app.controller('navWidgetCtrl', ['$scope', '$state', 'ngDialog', 'uiLoad', 'rest', 'user', function($scope, $state, ngDialog, uiLoad, rest, user) {
  $scope.isHideWrapper = true;
  if (user) {
    rest.post({
      methodId: '4012',
      data: {
        LandlordId: user.get('landlordId')
      },
      success: function(data) {
        if (data.code == "0") {
          var data = data.res.data;
          $scope.userType = data.userType;
          // status  -1=未申请 0=申请中 1=审核通过 2=审核不通过
          // identityType [0=未申请 1=业主 2=二房东（个人） 3=二房东（公司）]
          if (data.status == 0) {
          	if (data.identityType == 1) {
          		$state.go("nav.personal");
          	} else if (data.identityType == 2) {
          		$state.go("nav.personalLandlord");
          	} else if (data.identityType == 3) {
          		$state.go("nav.company");
          	}
          } else if (data.status == 1) {
            $state.go('app.houseOwner.list');
          	// location.href = "http://120.26.246.115:8020/index.html?landlordId=" + user.get('landlordId');
          } else {
            $scope.isHideWrapper = false;
            $scope.$digest()
          }
        } else {
          $scope.isHideWrapper = false;
          alert(data.res.msg);
        }
      },
      error: function() {}
    });
  }
  $scope.goPersonal = function(){
    if ($scope.userType) {
      if ($scope.userType == 1 ) {
        $state.go("nav.personal");
      }else{
        // alert("不可更改房东性质");
        ngDialog.openConfirm({
          template: 'js/module/fund/canNotChange.html',
          resolve: {
            load: function() {
                return uiLoad.load(['js/module/fund/canNotChange.js'])
            }
          },
          data:{
          },
          scope: $scope,
          width: 300,
          height: 150
        }).then(function(data) {

        }, function(reason) {

        });
      }
    }else{
      $state.go("nav.personal");
    }
  }
  $scope.goPersonalLandlord = function(){
    if ($scope.userType) {
      if ($scope.userType == 2 ) {
        $state.go("nav.personalLandlord");
      }else{
        // alert("不可更改房东性质");
        ngDialog.openConfirm({
          template: 'js/module/fund/canNotChange.html',
          resolve: {
            load: function() {
                return uiLoad.load(['js/module/fund/canNotChange.js'])
            }
          },
          data:{
          },
          scope: $scope,
          width: 300,
          height: 150
        }).then(function(data) {

        }, function(reason) {

        });
      }
    }else{
      $state.go("nav.personalLandlord");
    }
    
  }
  $scope.goCompany = function(){
    if ($scope.userType) {
      if ($scope.userType == 3 ) {
        $state.go("nav.company");
      }else{
        // alert("不可更改房东性质");
        ngDialog.openConfirm({
          template: 'js/module/fund/canNotChange.html',
          resolve: {
            load: function() {
                // return uiLoad.load(['js/module/fund/withdrawSuccess.js'])
            }
          },
          data:{
          },
          scope: $scope,
          width: 300,
          height: 150
        }).then(function(data) {

        }, function(reason) {

        });
      }
    }else{
      $state.go("nav.company");
    }
    
  }



}]);
